package com.koron.order.linedefect.defectDemotion.controller;

import com.github.pagehelper.PageInfo;
import com.koron.bean.base.Response;
import com.koron.bean.query.PageQuery;
import com.koron.common.core.config.ThreadLocalContext;
import com.koron.order.common.util.CheckPermission;
import com.koron.order.linedefect.defectDemotion.bean.po.DefectDemotionPo;
import com.koron.order.linedefect.defectDemotion.bean.query.DefectDemotionQuery;
import com.koron.order.linedefect.defectDemotion.service.DefectDemotionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.koron.ebs.mybatis.ADOConnection;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 缺陷工单下缺陷降级信息从表(DefectDemotion)表控制层
 *
 * @author zhouj
 * @since 2022-02-09 10:36:50
 */
@Api(tags = "线路缺陷工单下缺陷降级信息从表(DefectDemotion)")
@RestController("lineDefectDemotionController")
@RequestMapping("/lineDefectDemotion/")
public class DefectDemotionController {

    @Autowired
    private DefectDemotionService lineDefectDemotionService;

    private String getCurrDs() {
        return ThreadLocalContext.get().getCurrDs();
    }

    @ApiOperation(value = "新增或修改缺陷工单下缺陷降级信息从表")
    @PostMapping("insertOrUpdate")
    public Response<DefectDemotionPo> insertOrUpdate(@RequestBody DefectDemotionPo defectDemotion) {
        return Response.ok(ADOConnection.runTask(getCurrDs(), lineDefectDemotionService, "insertOrUpdate", DefectDemotionPo.class, defectDemotion));
    }

    @ApiOperation(value = "新增缺陷工单下缺陷降级信息从表")
    @PostMapping("insert")
    public Response<Integer> insert(@RequestBody DefectDemotionPo defectDemotion) {
        return Response.ok(ADOConnection.runTask(getCurrDs(), lineDefectDemotionService, "insert", Integer.class, defectDemotion));
    }

    @ApiOperation(value = "批量新增缺陷工单下缺陷降级信息从表")
    @PostMapping("insertBatch")
    public Response<Integer> insertBatch(@RequestBody List<DefectDemotionPo> defectDemotionList) {
        return Response.ok(ADOConnection.runTask(getCurrDs(), lineDefectDemotionService, "insertBatch", Integer.class, defectDemotionList));
    }

    @ApiOperation(value = "根据id更新缺陷工单下缺陷降级信息从表")
    @PutMapping("update")
    public Response<Integer> update(@RequestBody DefectDemotionPo defectDemotion) {
        return Response.ok(ADOConnection.runTask(getCurrDs(), lineDefectDemotionService, "update", Integer.class, defectDemotion));
    }

    @ApiOperation(value = "根据id删除缺陷工单下缺陷降级信息从表")
    @DeleteMapping("deleteById")
    public Response<Integer> deleteById(String id) {
        return Response.ok(ADOConnection.runTask(getCurrDs(), lineDefectDemotionService, "deleteById", Integer.class, id));
    }

    @ApiOperation(value = "根据id查询缺陷工单下缺陷降级信息从表")
    @CheckPermission
    @GetMapping("queryById")
    public Response<DefectDemotionPo> queryById(String id) {
        return Response.ok(ADOConnection.runTask(getCurrDs(), lineDefectDemotionService, "queryById", DefectDemotionPo.class, id));
    }

    @ApiOperation(value = "不分页查询缺陷工单下缺陷降级信息从表列表")
    @GetMapping("queryList")
    public Response<List> queryList(DefectDemotionPo queryVo) {
        return Response.ok(ADOConnection.runTask(getCurrDs(), lineDefectDemotionService, "queryList", List.class, queryVo));
    }

    @ApiOperation(value = "分页查询缺陷工单下缺陷降级信息从表列表")
    @GetMapping("queryVoPageList")
    public Response<PageInfo> queryVoPageList(DefectDemotionQuery demotionQuery, PageQuery pageQuery) {
        return Response.ok(ADOConnection.runTask(getCurrDs(), lineDefectDemotionService, "queryVoPageList", PageInfo.class, demotionQuery, pageQuery));
    }

    @ApiOperation(value = "提交")
    @GetMapping("submitDefectDemotion")
    public Response<Integer> submitDefectDemotion(String orderId, String status) {
        return Response.ok(ADOConnection.runTask(getCurrDs(), lineDefectDemotionService, "submitDefectDemotion", Integer.class, orderId, status));
    }

}
